import cv2
import numpy as np
if __name__ == '__main__':
    image=cv2.imread('caihong.jpg')
    #空间转换
    hsv_image=cv2.cvtColor(
        image,
        cv2.COLOR_BGR2HSV
    )
    #制作掩膜
    bule_low=np.array([112,43,46])#下限
    bule_high=np.array([124, 255, 255])#上限
    mask=cv2.inRange(
        hsv_image,#哪个图像
        bule_low,
        bule_high
    )
    #开运算降噪
    he = cv2.getStructuringElement(
        cv2.MORPH_ELLIPSE,
        (3, 3)
    )
    # 腐蚀 erode 或膨胀dilate函数
    morph_image = cv2.erode(
        mask,
        he
    )
    morph_image1 = cv2.dilate(
        morph_image,
        he
    )

    for i in range(morph_image1.shape[0]):
        for j in range(morph_image1.shape[1]):
            if morph_image1[i,j]==255:
                image[i,j]=(0,0,255)

cv2.imshow('image_np',image)
cv2.imshow('1',morph_image1)
cv2.waitKey(0)




